
//
//  WBStatusPictureView.swift
//  WeiBoAPP
//
//  Created by 张学飞 on 2019/7/31.
//  Copyright © 2019 zxf. All rights reserved.
//

import UIKit

class WBStatusPictureView: UIView {

    @IBOutlet weak var heightCons:NSLayoutConstraint!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        setupUI()
    }
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}



extension WBStatusPictureView {
    
    private func setupUI ()
    {
        clipsToBounds = true
        
        
        let  count = 9
        
        let leftSpace = CGFloat(20)
        //        let rightSpac = CGFloat(12.0)
        let betwwen = CGFloat(10)
        
        let width = UIScreen.main.bounds.size.width - 2 * leftSpace
        let picWidth = (width - 2 * betwwen) / 3
        
        let row = (count - 1) / 3 + 1
        var height = leftSpace
        height += CGFloat(row) * picWidth
        height += CGFloat(row - 1) * betwwen

        let rect = CGRect(x: 0, y: leftSpace, width: picWidth, height: picWidth)
        
        for i  in 0..<count {
            let view_img = UIImageView()
            view_img.backgroundColor = UIColor.red
            let row = CGFloat( i / 3)
            let col = CGFloat ( i % 3)
            let xoffset = col * (picWidth  + betwwen)
            let yoffset = row * (picWidth + betwwen)
            view_img.frame = rect.offsetBy(dx: xoffset, dy: yoffset)
            
            addSubview(view_img)
            
        }
        
        
    }
}
